import 'package:flutter/material.dart';
import 'package:shopping_group/main/lz_mall/model/lz_mall_category_prduct_model.dart';
import 'package:shopping_group/main/lz_mall/view_model/lz_mall_home_view_model.dart';
import 'package:shopping_group/main/lz_mall/widgets/lz_mall_homr_product_widget.dart';
import 'package:shopping_group/res/dimens.dart';
import 'package:shopping_group/utils/widget_utils.dart';

class LzMallProductPage extends StatefulWidget {
  final LzCategoryProductModel categoryProductModel;
  LzMallProductPage({Key key, this.categoryProductModel}) : super(key: key);

  @override
  _LzMallProductPageState createState() => _LzMallProductPageState();
}

const String MallProductPage = "mall_product_page";

class _LzMallProductPageState extends State<LzMallProductPage> {
  List<LstCommoSpec> dataList = [];

  @override
  void initState() {
    super.initState();

    LzMallHomeViewModel().getCategoryAll(widget.categoryProductModel.id, (value) {
      dataList.addAll(value);
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        resizeToAvoidBottomInset: false,
        backgroundColor: Color(0xFFFFFFFF),
        appBar: WidgetUtils.showAppar(context, widget.categoryProductModel.name, textColor: Colors.white),
        body: Container(
          child: GridView.builder(
            padding: EdgeInsets.zero,
            controller: ScrollController(keepScrollOffset: false), //靜止滾動事件
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 2, crossAxisSpacing: 1, mainAxisSpacing: 1, childAspectRatio: 12 / 15), //子纵比例
            shrinkWrap: true, //收缩包装
            itemBuilder: (context, index) {
              LstCommoSpec lstCommoSpec = dataList[index];
              return EcMallHomeProductWidget(lstCommoSpec);
            },
            itemCount: dataList.length,
          ),
        ));
  }
}
